import jsonp from "jsonp";
import ajax from "./ajax";

export const reqLogin = (username, password) =>
  ajax("/api/login", { username, password }, "POST");
export const reqAddUser = (user) => ajax("/api/manage/user/add", user, "POST");
export const reqWeather = (city) =>
  ajax(
    "/weather",
    {
      cityNm: city,
      app: "weather.today",
      appkey: 63272,
      sign: "c6578f0f5dd69555f9462bc29c665369",
      format: "json",
    },
    "GET"
  );

export const reqCategoryList = (parentId = "0") =>
  ajax("/api/manage/category/list", { parentId });

export const reqAddCategory = (parentId, categoryName) =>
  ajax("/api/manage/category/add", { parentId, categoryName }, "POST");

export const reqUpdateCategory = ({ categoryId, categoryName }) =>
  ajax("/api/manage/category/update", { categoryId, categoryName }, "POST");

export const reqProductList = ({ pageNum, pageSize }) =>
  ajax("/api/manage/product/list", { pageNum, pageSize });

export const reqSearchProducts = ({
  pageNum,
  pageSize,
  searchType,
  searchValue,
}) =>
  ajax("/api/manage/product/search", {
    pageNum,
    pageSize,
    [searchType]: searchValue,
  });

export const reqPhone = (num) => {
  const phoneUrl = `https://api.asilu.com/phone/?phone=${num}`;

  jsonp(phoneUrl, {}, (err, data) => {
    if (!err) {
      console.log("success----", data);
    } else {
      console.log("error-----", err);
    }
  });
};
// let num = 13294130625;
// reqPhone(num);
